﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WoSoft.PACS.Data.TemplateData;

namespace WoSoft.PACS.Win.Forms.SubForms
{
    public partial class FrmOutlineWords : FrmBase
    {
        private OutlineWordsDataService wordsDs = new OutlineWordsDataService();
        private string _cid;
        private string _wordsID;

        public FrmOutlineWords(string cid, string id)
        {
            InitializeComponent();
            _cid = cid;
            _wordsID = id;
        }


        //保存确定
        private void buttonX1_Click(object sender, EventArgs e)
        {
            this.errorProvider1.Clear();
            if (this.tbName.Text.Trim() == string.Empty)
            {
                this.errorProvider1.SetError(this.tbName, "请填写名称");
                return;
            }

            if (this.tbContent.Text.Trim()==string.Empty)
            {//请填写词句内容
                this.errorProvider1.SetError(this.tbContent, "请填写内容");
                return;
            }

            var cnt = 0;
            if (string.IsNullOrEmpty(this._wordsID))
            {
                //增加
                cnt = wordsDs.Insert(this._cid, this.tbName.Text.Trim(), this.tbComment.Text.Trim(), this.tbContent.Text.Trim());
            }
            else
            {
                //更新
                cnt = wordsDs.Update(this._wordsID, this.tbName.Text.Trim(), this.tbComment.Text.Trim(), this.tbContent.Text.Trim());
            }

            if (cnt>0)
            {
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
            }
        }

        //取消关闭
        private void buttonX2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void FrmOutlineWords_Load(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this._wordsID)) return;

            var dt = wordsDs.GetModelByID(this._wordsID);

            if (dt.Rows.Count > 0)
            {
                tbName.Text = dt.Rows[0]["名称"].ToString();
                tbContent.Text = dt.Rows[0]["内容"].ToString();
                tbComment.Text = dt.Rows[0]["注释"].ToString();
            }
        }


    }
}
